﻿using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace CloudShot.Editor
{
  public class FigureColorScheme
  {
    public Color BorderColor { get; private set; }
    public Color BackColor { get; private set; }
    public Color TextColor { get; private set; }

    public FigureColorScheme(Color backColor, Color borderColor, Color textColor)
    {
      BorderColor = borderColor;
      BackColor = backColor;
      TextColor = textColor;
    }
  }

  //TODO maybe this class should be merged with FigurePropViewModel, seems they have same responsibility
  public struct FigureSettings
  {
    public Color BackColor { get; set; }
    public byte BackgroundOpacity { get; set; }
    public Color BorderColor { get; set; }
    public int BorderWidth { get; set; }
    public Color TextColor { get; set; }
    public float FontSize { get; set; }
    public LineType LineType { get; set; }
    public bool IsArrowAtStart { get; set; }
    public bool IsArrowAtEnd { get; set; }
    public int Width { get; set; }
    public int Height { get; set; }
  }

  public class EditorTheme
  {
    private const float DefaultFontSize = 12;
    private const int DefaultFigureWidth = 150;
    private const int DefaultFigureHeight = 100;

    private readonly float[] _fontSizes = { 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };

    public const int MinimumFigureSize = 16;
    public static readonly Size DefaultCropSize = new Size(450, 350);//TODO: maybe will be better to create FigureSettings CropSettings property

    public IEnumerable<float> FontSizes
    {
      get { return _fontSizes; }
    }

    public FigureColorScheme[] FigureColorSchemes { get; private set; }
    public IEnumerable<Color> BackColors { get; private set; }
    public IEnumerable<Color> BorderColors { get; private set; }
    public IEnumerable<Color> TextColors { get; private set; }

    public int BorderWidth1 { get; private set; }
    public int BorderWidth2 { get; private set; }
    public int BorderWidth3 { get; private set; }
    public int BorderWidth4 { get; private set; }

    public byte BackgroundOpacity1 { get; private set; }
    public byte BackgroundOpacity2 { get; private set; }
    public byte BackgroundOpacity3 { get; private set; }
    public byte BackgroundOpacity4 { get; private set; }

    public FigureSettings TextSettings { get; private set; }
    public FigureSettings ArrowSettings { get; private set; }
    public FigureSettings LineSettings { get; private set; }
    public FigureSettings FrameSettings { get; private set; }
    public FigureSettings RectangleSettings { get; private set; }
    public FigureSettings EllipseSettings { get; private set; }

    public EditorTheme()
    {
      var white = Color.FromArgb(255, 255, 255);
      var black = Color.FromArgb(0, 0, 0);

      var purpleLight = Color.FromArgb(128, 100, 162);
      var purpleDark = Color.FromArgb(76, 59, 98);

      var redLight = Color.FromArgb(255, 76, 76);
      var redDark = Color.FromArgb(127, 38, 38);

      var greenLight = Color.FromArgb(182, 215, 168);
      var greenDark = Color.FromArgb(49, 97, 24);

      var yellowLight = Color.FromArgb(255, 229, 153);
      var yellowDark = Color.FromArgb(157, 120, 0);

      var marineLight = Color.FromArgb(159, 197, 248);
      var marineDark = Color.FromArgb(9, 69, 123);

      var orangeLight = Color.FromArgb(255, 153, 0);
      var orangeDark = Color.FromArgb(149, 79, 5);

      var colors = new List<Color>
      {
        white, purpleLight, redLight, greenLight, yellowLight, marineLight, orangeLight,
        black, purpleDark, redDark, greenDark, yellowDark, marineDark, orangeDark 
      };

      FigureColorSchemes = new[]
      {
        new FigureColorScheme(white, black, black),
        new FigureColorScheme(black, white, white),
        new FigureColorScheme(purpleLight, purpleDark, purpleDark),
        new FigureColorScheme(purpleDark, purpleLight, purpleLight),
        new FigureColorScheme(redLight, redDark, redDark),
        new FigureColorScheme(redDark, redLight, redLight),
        new FigureColorScheme(greenLight, greenDark, greenDark),
        new FigureColorScheme(greenDark, greenLight, greenLight),
        new FigureColorScheme(yellowLight, yellowDark, yellowDark),
        new FigureColorScheme(yellowDark, yellowLight, yellowLight),
        new FigureColorScheme(marineLight, marineDark, marineDark),
        new FigureColorScheme(marineDark, marineLight, marineLight),
        new FigureColorScheme(orangeLight, orangeDark, orangeDark),
        new FigureColorScheme(orangeDark, orangeLight, orangeLight)
      };

      BackColors = colors;
      BorderColors = colors;
      TextColors = colors;

      BorderWidth1 = 1; //px
      BorderWidth2 = 3; //px
      BorderWidth3 = 5; //px
      BorderWidth4 = 7; //px

      BackgroundOpacity1 = 0;
      BackgroundOpacity2 = (75 * 255) / 100;
      BackgroundOpacity3 = (90 * 255) / 100;
      BackgroundOpacity4 = (100 * 255) / 100;

      TextSettings = new FigureSettings
      {
        BackColor = white,
        BorderColor = redDark,
        BorderWidth = BorderWidth1,
        LineType = LineType.None,
        TextColor = redDark,
        BackgroundOpacity = BackgroundOpacity1,
        FontSize = DefaultFontSize,
        Width = 270,
        Height = 32,
      };

      FrameSettings = new FigureSettings
      {
        BackColor = redLight,
        BorderColor = redDark,
        BorderWidth = BorderWidth2,
        TextColor = white,
        BackgroundOpacity = BackgroundOpacity1,
        LineType = LineType.Solid,
        Width = DefaultFigureWidth,
        Height = DefaultFigureHeight
      };

      EllipseSettings = new FigureSettings
      {
        BackColor = redLight,
        BorderColor = redDark,
        BorderWidth = BorderWidth1,
        TextColor = white,
        LineType = LineType.Solid,
        Width = DefaultFigureWidth,
        Height = DefaultFigureHeight
      };

      LineSettings = new FigureSettings
      {
        BackColor = redLight,
        BorderColor = redDark,
        BorderWidth = BorderWidth2,
        TextColor = white,
        LineType = LineType.Solid,
        Width = DefaultFigureWidth,
        Height = DefaultFigureHeight
      };

      ArrowSettings = new FigureSettings
      {
        BackColor = redLight,
        BorderColor = redDark,
        BorderWidth = BorderWidth2,
        TextColor = white,
        LineType = LineType.Dash,
        IsArrowAtStart = true,
        IsArrowAtEnd = false,
        Width = DefaultFigureWidth,
        Height = DefaultFigureHeight
      };

      RectangleSettings = new FigureSettings
      {
        BackColor = redLight,
        BorderColor = redDark,
        BorderWidth = BorderWidth1,
        TextColor = white,
        BackgroundOpacity = BackgroundOpacity4,
        LineType = LineType.Solid,
        Width = DefaultFigureWidth,
        Height = DefaultFigureHeight
      };
    }
  }
}